﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LinQ_DTO;
namespace DAO
{
    public class PathsDAO
    {
        public List<aspnet_Path> LayTatCaPath()
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            var Path = from p in EFashionDB.aspnet_Paths
                       select p;

            return Path.ToList();
        }

        public List<aspnet_Path> LayTatCaPathTheoID(Guid ID)
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            var Path = from p in EFashionDB.aspnet_Paths
                       where p.PathId == ID
                       select p;

            return Path.ToList();
        }

        public List<aspnet_Application> LayApplicationsTheoPath(Guid ID)
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            var App = from p in EFashionDB.aspnet_Paths
                      from app in EFashionDB.aspnet_Applications
                       where p.PathId == ID && app.ApplicationId == p.ApplicationId
                       select app;

            return App.ToList();
        }

        public void XoaApplicationTheoID(Guid ID)
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            var Path = from p in EFashionDB.aspnet_Paths
                       where p.PathId == ID
                       select p;

            EFashionDB.aspnet_Paths.DeleteAllOnSubmit(Path);
            EFashionDB.SubmitChanges();

            
        }

        public void ThemPath(aspnet_Path path)
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            EFashionDB.aspnet_Paths.InsertOnSubmit(path);
            EFashionDB.SubmitChanges();
        }

        public void XoaPathTheoID(Guid ID)
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            var Path = from p in EFashionDB.aspnet_Paths
                       where p.PathId == ID
                       select p;

            EFashionDB.aspnet_Paths.DeleteAllOnSubmit(Path);
            EFashionDB.SubmitChanges();


        }

        public void CapNhatPath(Guid ID, string Path, string LoweredPath)
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            var ListPath = from p in EFashionDB.aspnet_Paths
                           where p.PathId == ID
                           select p;
            foreach (aspnet_Path paths in ListPath)
            {
                paths.Path = Path;
                paths.LoweredPath = LoweredPath;
            }

            EFashionDB.SubmitChanges();
        }

    }
}
